/**
 *	\file
 *	\brief represents an hash table storing all the labels
 *
 * 	\date Sep 12, 2013
 * 	\author koldar
 *	\version 1.0
 */

#ifndef LABELHASHTABLE_H_
#define LABELHASHTABLE_H_

#include "uthash.h"
#include "LabelHTCell.h"
#include <stdbool.h>

#define __LABEL_HASH_TABLE_BUFFER_SIZE__ 50

/**typedef used to improve code readability
 *
 */
typedef LabelHTCell* LabelHashTable;

/**can be used to refer the very hash table in the parameter transmission. For further information
 * visit http://troydhanson.github.io/uthash/userguide.html#_add_item
 *
 */
typedef LabelHTCell** PlabelHashTable;

/**initialize correctly the hash table
 *
 * \pre
 *  \li phashtable must not be already in use (otherwise memory leak might arise)
 *
 * @param phashtable the hash table to initialize correctly
 */
void initLabelHashTable(PlabelHashTable phashtable);

/**find a label in the hash table.
 *
 * \pre
 *  \li key not NULL;
 *  \li phashtable not NULL;
 *
 * @param phashtable the talbe to search into
 * @param key the key of the label to look for
 * @return a pointer to the label or NULL if not present
 */
Plabel findLabelInHashTable(PlabelHashTable phashtable,const char* key);

/**add a label in the current hash table. phashtable might be NULL
 *
 * \pre
 *  \li label is not present in the hash table
 *  \li label must not be NULL
 *
 * @param phashtable the has table which will store the label
 * @param label the label to store
 */
void addLabelInHashTable(PlabelHashTable phashtable, Plabel label);

/**free and destroy the label hash table
 *
 * \pre
 *  \li phashtable must not be NULL
 * \post
 *  \li the hash table is correctly freed form the memory
 *
 * @param phashtable the hash table to deallocate
 */
void freeLabelHashTable(PlabelHashTable phashtable);

/**generates a graph representing this hash table
 *
 * \pre
 *  \li filename is a correct Linux file name;
 *  \li filename does not contain any "/" character;
 * \post
 *  \li a file called "filename".jpg is created in the grp directory
 *
 * @param filename represents the name of the image representing this hashtable
 * @param phashtable the hash table to be drawn
 * @return TRUE if all the operation has been completed, FALSE otherwise
 */
bool buildLabelHashTableGraph(char* filename,PlabelHashTable phashtable);


#endif /* LABELHASHTABLE_H_ */
